package com.example.myapplication.logisticsinquiry;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.LogisticsinquirynoBean;
import com.example.myapplication.apter.LogisticsdetailsApter;
import com.google.gson.Gson;

public class LogisticsinquirynoActivity extends AppCompatActivity {

    private LogisticsinquirynoBean logisticsinquirynoBean;
    private ImageView img;
    private TextView infoNo;
    private RecyclerView re_material;
    private ImageView imgUrl;
    private TextView complain;
    private Gson gson;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_logisticsinquiryno);
        initview();
        //返回
        but_loak();
        //填充信息
        materialflow();

    }

    private void but_complain(LogisticsinquirynoBean logisticsinquirynoBean) {
        complain.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LogisticsinquirynoActivity.this,ComplainActivity.class);
                String COMPANYID = gson.toJson(logisticsinquirynoBean);
                intent.putExtra(Commom.COMPANYID,COMPANYID);
                LogisticsinquirynoActivity.this.startActivity(intent);
            }
        });
    }

    private void materialflow() {
        LogisticsinquirynoBean.DataBean data = logisticsinquirynoBean.getData();
        infoNo.setText(data.getInfoNo());
        Glide.with(this).load(TokenBean.IP+data.getCompany().getImgUrl()).into(imgUrl);
    }

    private void but_loak() {
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                LogisticsinquirynoActivity.this.finish();
            }
        });
    }

    private void initview() {
        Intent intent = getIntent();
        String stringExtra = intent.getStringExtra(Commom.logisticsinquirynoBeanString);
        gson = new Gson();
        logisticsinquirynoBean = gson.fromJson(stringExtra, LogisticsinquirynoBean.class);



        img = findViewById(R.id.img);
        imgUrl = findViewById(R.id.imgUrl);
        infoNo = findViewById(R.id.infoNo);
        re_material = findViewById(R.id.re_Material);
        complain = findViewById(R.id.complain);


        //物流详情
        logisticsdetails(logisticsinquirynoBean);
        //点击投诉
        but_complain(logisticsinquirynoBean);
    }

    private void logisticsdetails(LogisticsinquirynoBean logisticsinquirynoBean) {
        re_material.setLayoutManager(new LinearLayoutManager(this));
        re_material.setAdapter(new LogisticsdetailsApter(this,logisticsinquirynoBean.getData().getStepList()));
    }
}